import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store/index";
// import Layout from '@/views/layout'
// import Centre from '@/views/centre'
// import Order from '@/views/order'
const login = () => import("@/views/login/Index.vue");
const layout = () => import("@/views/Layout.vue");
const centre = () => import("@/views/Centre.vue");
const userList = () => import("@/views/UserList.vue");
const teamList = () => import("@/views/TeamList.vue");
const teamTree = () => import("@/views/TeamTree.vue");
const pureMoneyInto=()=>import("@/views/PureMoneyInto.vue");
const intoMoneyNum=()=>import("@/views/IntoMoneyNum.vue");
const outMoneyNum=()=>import("@/views/OutMoneyNum.vue");
const userIntoQuery=()=>import("@/views/UserIntoQuery.vue");
const newAddOrderNum=()=>import("@/views/NewAddOrderNum.vue");
const intoMoneyRank=()=>import("@/views/IntoMoneyRank.vue");
const outMoneyRank=()=>import("@/views/OutMoneyRank.vue");
Vue.use(VueRouter)

  const routes = [
  { path: "/", redirect: "/index" },
    { path: "/index", redirect: "/login" },  // hey 修改
  {
    path: '/login',
    name: 'login',
    component: login,
  },
    {
      path: '/layout',
      name: 'layout',
      menu_index:'1',
      component: layout,
      children: [
        // {
        // path: '/centre',  //layout首页
        // name: 'centre',
        // component: centre
        // },
        {
          path: '/userList',//用户列表
          name: 'userList',
          meta: {menu_index: "1-1" },
          component: userList

        },
        {
          path: '/teamList',  //团队列表
          name: 'teamList',
          meta: {menu_index: "1-2" },
          component: teamList
      },
        {
          path: '/teamTreeList',  //团队树型列表
          name: 'teamTreeList',
          meta: {menu_index: "1-3" },
          component: teamTree
        },
        {
          path: '/pureMoneyInto',  //净资金流入
          name: 'pureMoneyInto',
          meta: {menu_index: "2-1" },
          component: pureMoneyInto
        },
        {
          path: '/intoMoneyNum',  //出金统计
          name: 'intoMoneyNum',
          meta: {menu_index: "2-2" },
          component: intoMoneyNum
        },
        {
          path: '/outMoneyNum',  //入金统计
          name: 'outMoneyNum',
          meta: {menu_index: "2-3" },
          component: outMoneyNum
        },
        {
          path: '/userIntoQuery',  //入金统计
          name: 'userIntoQuery',
          meta: {menu_index: "2-4" },
          component: userIntoQuery
        },
        {
          path: '/newAddOrderNum',  //新增持仓
          name: 'newAddOrderNum',
          meta: {menu_index: "2-5" },
          component: newAddOrderNum
        },
        {
          path: '/intoMoneyRank',  //入金团队排行
          name: 'intoMoneyRank',
          meta: {menu_index: "3-1" },
          component: intoMoneyRank
        },
        {
          path: '/outMoneyRank',  //出金团队排行
          name: 'outMoneyRank',
          meta: {menu_index: "3-2"},
          component: outMoneyRank
        }]
    },
]
let router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  let token =localStorage.getItem("token")
  let readyPromise = null;
  let readyPromiseRS = null;
  readyPromise = new Promise(resolve => {
    readyPromiseRS = resolve;
  });
  readyPromiseRS();
  readyPromise.then(() => {
    if(token && to.path==='/login'){
      next('/userList')
    }else if(!token && to.path!=='/login'){  // hey修改
      next('/login')
    }else{
      store.state.left_menu=to.meta.menu_index;
      next()
    }
  });

})
export default router
